package org.example.completed.controller;

import org.example.completed.domain.Reservation;
import org.example.completed.domain.User;
import org.example.completed.mapper.UserMapper;
import org.example.completed.model.dto.RegisterDto;
import org.example.completed.model.vo.ResultVO;
import org.example.completed.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 参观大活动
 */
@RestController
@RequestMapping("/reservations")
public class ReservationController {
    @Autowired
    private ReservationService reservationService;

    /**
     * 获取所有参观预约信息
     * @return
     */
    @GetMapping
    public ResultVO<List<Reservation>> getAllReservations() {
        List<Reservation> reservations = reservationService.list();  // 获取预约信息
        return ResultVO.ok(reservations, "获取所有预约信息成功");  // 使用 ResultVO 返回结果
    }

    /**
     * 后台新增参观活动
     * @param reservation
     * @return
     */
    @PostMapping
    public ResultVO<Boolean> addReservation(@RequestBody Reservation reservation) {

        boolean res = reservationService.save(reservation);
        return res ? ResultVO.ok(true) : ResultVO.fail("新增参观信息失败");
    }

    /**
     * 用户报名参观接口
     * @param request 包含用户ID、联系信息和参观时间的请求体
     * @return 操作结果
     */
    @PostMapping("/register")
    public ResultVO<Boolean> register(@RequestBody RegisterDto request) {
        boolean result = reservationService.register(request.getUserId(), request.getContact(), request.getVisitTime());
        return result ? ResultVO.ok(true) : ResultVO.fail("报名用户不存在 或 用户已报名");
    }

}